וַיֹּ֣אמֶר דָּוִ֔יד זֶ֣ה ה֔וּא בֵּ֖ית יְהוָ֣ה הָאֱלֹהִ֑ים וְזֶה־מִּזְבֵּ֥חַ לְעֹלָ֖ה לְיִשְׂרָאֵֽל׃ (ס)
און דוד האָט געזאָגט: דאָס איז דאָס הױז פֿון גאָט דעם האַר, און דאָס איז דער מזבח פֿאַר בראַנדאָפּפֿער פֿאַר ישׂראל.
Midrash Tehillim
Another interpretation of "Bikrei Anani" (a phrase from the beginning of Psalm 18): There were three things that troubled David, but God comforted him. The first was the destruction of the Temple. As it says (Psalm 132:1), "Remember, O Lord, for David all his hardships." And God comforted him by revealing to him the place where the Temple would be built, as it says (1 Chronicles 22:1), "Then David said, 'This is the house of the Lord God.'" The second thing that troubled David was the sin with Bathsheba. The people of Israel were saying that David deserved to die for what he had done. But God comforted him by saying (2 Samuel 12:13), "The Lord has taken away your sin. You will not die." The third thing that troubled David was the question of who would succeed him as king. God comforted him by promising that his son Solomon would be his successor, as it says (1 Chronicles 22:9-10), "Behold, a son will be born to you...and his name shall be Solomon...I will establish his kingdom forever." And when David asked, "Who will be born to me?" God replied, "Through whom will you be healed of your sins? Through the son of the woman with whom you sinned." This was revealed to David by the prophet Nathan, as it says (2 Samuel 12:25), "And he sent word through Nathan the prophet, and he named him Jedidiah."
Pesikta Rabbati
... “He does the will of those who fear Him…” (Tehillim 145:19) Meaning that Gd does not annul his prayers and gives him what he requests. This refers to David, of whom it is written “I am a companion to all who fear You…” (Tehillim 119:63) at the time when he was troubled over the Holy Temple, as it is written “Remember, O Lord, onto David all his affliction. That he swore to the Lord, he vowed to the Mighty One of Jacob; That I shall not come into the tent of my house, and I shall not go up on the bed that was spread for me. I shall not give sleep to my eyes nor slumber to my pupils, Until I find a place for the Lord, dwellings for the Mighty One of Jacob.” (Tehillim 132:1-5) Since the Holy One saw that he stood there, troubled over the Holy Temple, He immediately sent Gad the prophet to him and showed him the place of the Holy Temple, as it is written “And Gad came to David on that day, and said to him, ‘Go up to erect an altar to the Lord in the threshing-floor of Aravnah the Jebusite.’” (Shmuel II 24:18) David went there immediately, as it says “And David went up according to the word of Gad, as the Lord had commanded. (Shmuel II 24:19) He found there the altar where Adam, the first man, made offerings, where Noach made offerings, where Avraham made offerings. Once he found it he began to measure, saying ‘from here to here will be the Courtyard, from here to here will be the Holy of Holies’ as it says “And David said, ‘This is the House of the Lord God…” (Divre HaYamim I 22:1) And how could he declare “…and this is the altar for burnt offerings for Israel” (ibid.)? This is what is meant that the Holy One does not nullify the desire of the righteous, but rather gives them what they seek in order to fulfill “He does the will of those who fear Him…” (Tehillim 145:19)